/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * pnlBeginCalibration.java
 *
 * Created on Nov 9, 2011, 1:21:24 AM
 */
package GUI;

import java.awt.Dimension;
import java.awt.Frame;
import javax.swing.JFrame;
import javax.swing.SwingWorker;

import pantomime.gestures.GestureMain;
import GUI.Pantomime;
import processing.core.PApplet;


/**
 *
 * @author Pavel - Old Macbook Pro
 */
public class pnlBeginCalibration extends javax.swing.JPanel
	implements Runnable{

    /** Creates new form pnlBeginCalibration */
    public pnlBeginCalibration() {
    	this.setPreferredSize(new Dimension(500, 200));
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
    	
        pbCalibrationProgress = new javax.swing.JProgressBar(0, 6000);
     
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        lblCalibrationProgress = new javax.swing.JLabel();

        jButton1.setText("Cancel");
        
        jButton2.setText("Begin");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton2MouseReleased(evt);
            }
        });

        lblCalibrationProgress.setText("Hold your hand flat to begin calibration.        ");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(

            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(76, 76, 76)
                .add(jLabel1)
                .addContainerGap(276, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .add(33, 33, 33)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(lblCalibrationProgress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(jButton2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 86, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(pbCalibrationProgress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(31, 31, 31)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(lblCalibrationProgress)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(pbCalibrationProgress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton2)
                    .add(jButton1))
                .addContainerGap(36, Short.MAX_VALUE))
        );
        this.setSize(300,200);
    }// </editor-fold>//GEN-END:initComponents
    
    private void jButton2MouseReleased(java.awt.event.MouseEvent evt) {
    	Thread animation = new Thread(this);
    	animation.start();   	
    }

    	public void run(){
    		lblCalibrationProgress.setText("Hold your hand flat to begin calibration.          ");
    		
    		long msElapsed = 0;
        	long msCalBegin = System.currentTimeMillis();
        	boolean bSet = false;
        	while(msElapsed < 8000){
        		if(msElapsed > 4000 && ! bSet){
        			lblCalibrationProgress.setText("Hold your hand in a fist to continue calibration.");
        		}
            	msElapsed =  (System.currentTimeMillis() - msCalBegin);
            	pbCalibrationProgress.setValue((int)msElapsed);   		
        	}
        	
        	lblCalibrationProgress.setText("Calibration Complete!                                          ");
            // TODO add your handling code here:
    	}
    	
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel lblCalibrationProgress;
    private javax.swing.JProgressBar pbCalibrationProgress;
    // End of variables declaration//GEN-END:variables
}
